#ifndef QDRIVERFACTORY_H
#define QDRIVERFACTORY_H

#include "sharedlibglobal.h"

#include <QMetaObject>
#include <QMap>
#include <QString>

class QAbstractDriver;
class XMLObject;

struct tagDriverInfo
{
    const QMetaObject *m_driver_object;
    QString         m_name;
    QString         m_show_name;
    QString         m_show_group;
    int             m_show_index;
};

class SHAREDLIB_EXPORT QDriverFactory
{
public:
    QDriverFactory(const QString &name,
                   const QString &show_name,
                   const QString &show_group,
                   int            show_index,
                   const QMetaObject* driver);

public:
    static void register_driver(const QString &name,
                                const QString &show_name,
                                const QString &show_group,
                                int            show_index,
                                const QMetaObject* driver);
    static QAbstractDriver* create_driver(const QString& name);
    static QList<tagDriverInfo*> get_driver_info();
    static tagDriverInfo *  get_driver_info(const QString &name);
protected:
    static void sort();
protected:
    static QMap<QString,tagDriverInfo*>        *m_meta_map;
    static QList<tagDriverInfo*>               *m_metas;
};


#ifndef qRegisterDriver
    #define qRegisterDriver(name,class_name,index)\
            QDriverFactory factory_##class_name(name,\
                                                class_name::get_show_name(),\
                                                class_name::get_show_group(),\
                                                index,\
                                                &class_name::staticMetaObject);
#endif
#endif // QDRIVERFACTORY_H
